package com.v1nsai.dataoff;

import java.util.Timer;
import java.util.TimerTask;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.wifi.WifiManager;
import android.os.Handler;


public class ScreenOn extends BroadcastReceiver{
	
	public void onReceive(Context context, Intent intent) {
		//declare and initialize
		final WifiManager wm = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
		final Handler handler = new Handler();
		SharedPreferences prefs = context.getSharedPreferences(Settings.PREFS_NAME, 0);
		Timer t = new Timer();
		
		//turn on wifi after delay set in Settings
		if(prefs.getBoolean(Settings.WIFI_KILL, false) == true )
		{
			t.schedule(new TimerTask() { 
				public void run() { 
					handler.post(new Runnable() { 
						public void run() { 
							if(wm.isWifiEnabled() == false)
								wm.setWifiEnabled(true);
						}	
	                }); 
				} 
	        }, prefs.getInt(Settings.WIFI_ONDELAY, 0) * 1000); 
		}
	}
}




